<?php

use yii\helpers\Url;
use yii\bootstrap\ActiveForm;

$this->context->layout = false;
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<div id="TeamentryList"></div>
<script type="text/x-kendo-template" id="TeamentryTime">
    <input type="text" id="T_date_start" name="T_date_start" value="<?= $time['T_date_start'] ?>" placeholder="开始月份">
    <input type="text" id="T_date_end" name="T_date_end" value="<?= $time['T_date_end'] ?>" placeholder="结束月份">
</script>
<script id="teamentry-popup-editor" type="text/x-kendo-template">
    <div class="m-box">
        <table class="table">
            <tr>
                <th width="20%">
                    <label for="department_name">部門</label>
                </th>
                <td width="30%">
                    <input id="department_name" type="text" readonly name="department_name"
                           value="#: department_name #">
                </td>
                <th width="20%"><label for="group_name">組別</label></th>
                <td width="30%">
                    <input type="text" readonly id="group_name" name="group_name" value="#: group_name #">
                </td>
            </tr>
            <tr>
                <th width="20%"><label for="name_cn_long">中文名</label></th>
                <td width="30%">
                    <input type="text" id="name_cn_long" readonly name="name_cn_long" value="#: name_cn_long #"/>
                </td>
                <th width="20%"><label for="name_en_long">英文名</label></th>
                <td width="30%">
                    <input type="text" id="name_en_long" readonly name="name_en_long" value="#: name_en_long #"/>
                </td>
            </tr>

            <tr>
                <th width="20%"><label for="created">美國時間</label></th>
                <td width="30%">
                    <input type="text" id="created" readonly name=""
                           value="#: kendo.toString(new Date(created),'MM/dd/yyyy HH:mm') #">
                </td>

                <th width="20%"><label for="deductions_situation">扣款情況</label></th>
                <td width="30%">
                    <input type="text" id="deductions_situation" readonly
                           value="# if(typeof deductions_situation==='object'){ # 0 # }else{ # #: deductions_situation # # } #元/次"/>
                </td>
            </tr>

            <tr>
                <th width="20%"><label for="column_name">三類別</label></th>
                <td width="30%" data-container-for="column_id">
                    <input id="column_name" name="column_id" validationmessage="請選擇類別" value="#: column_name #"
                           required="required"/>
                </td>

                <th width="20%"><label for="type_name">五大類</label></th>
                <td width="30%" data-container-for="type_id">
                    <span id="type_name_message" style="display: none">無</span>
                    <input id="type_name" name="type_id" validationmessage="請選擇五大類" value="#: type_name #"
                           required="required"/>
                </td>
            </tr>

            <tr>
                <th width="20%"><label for="level1">錯誤一類級別</label></th>
                <td width="30%" data-container-for="level1_id">
                    <span id="level1_message" style="display: none">無</span>
                    <input id="level1" name="level1_id" value="#: level1 #"/>
                </td>

                <th width="20%"><label for="level2">錯誤二類級別</label></th>
                <td width="30%" data-container-for="level2_id">
                    <span id="level2_message" style="display: none">無</span>
                    <input id="level2" name="level2_id" value="#: level2 #"/>
                </td>
            </tr>


            <tr>
                <th width="20%"><label for="content">詳情</label></th>
                <td colspan="3" data-container-for="content">
                    <textarea style="width:90%;height:100px" id="content" name="content">#: content #</textarea>
                </td>
            </tr>

            <tr>
                <th width="20%"><label for="teamentry_affected_department">被影響部門</label></th>
                <td colspan="3" data-container-for="affected_department">
                    <span id="teamentry_affected_department_message" style="display: none">無</span>
                    <select id="teamentry_affected_department" validationmessage="請選擇被影響部門" name="affected_department"
                            required="required"></select>
                </td>
            </tr>

            <tr>
                <th width="20%"><label for="teamentry_affected_group">被影響組別</label></th>
                <td colspan="3" data-container-for="affected_group">
                    <span id="teamentry_affected_group_message" style="display: none">無</span>
                    <select id="teamentry_affected_group" name="affected_group"></select>
                </td>
            </tr>

                <tr>
                    <th width="20%"><label for="tag_name">警告信</label></th>
                    <td colspan="3" data-container-for="tag">
                        <input id="tag_name" name="tag" required="" value="#: tag_name #" validationmessage="請選擇警告信"/>
                    </td>
                </tr>
            <?php if (isset($department) && $department == 1): ?>
                <tr>
                    <th width="20%"><label for="rating_name">評級</label></th>
                    <td colspan="3" data-container-for="rating_id">
                        <input required id="rating_name" name="rating_id" value="#: rating_name #"
                               validationmessage="請選擇評級"/>
                    </td>
                </tr>
            <?php endif ?>
        </table>
    </div>
</script>
<script>
    var AllTypeList, ColumnData, TagList, Rating, affectedDepartment, affectedGroup;
    var _dataSource = new kendo.data.DataSource({
        data: []
    });
    $.ajax({
        type: "GET",
        async: false,
        url: "<?=Url::toRoute(['/hr/pick/default/getalltype']); ?>",
        dataType: "json",
        success: function (data) {
            AllTypeList = data;
        }
    });
    $.ajax({
        type: "GET",
        async: false,
        url: "<?=Url::toRoute(['/hr/pick/default/getallrating']); ?>",
        dataType: "json",
        success: function (data) {
            Rating = data;
        }
    });
    $.ajax({
        type: "GET",
        async: false,
        url: "<?=Url::toRoute(['/hr/pick/default/gettagview']); ?>",
        dataType: "json",
        success: function (data) {
            TagList = data;
        }
    });
    $.ajax({
        type: "GET",
        async: false,
        url: "<?=Url::toRoute(['/hr/pick/default/gettype', 'pid' => 0]); ?>",
        dataType: "json",
        success: function (data) {
            ColumnData = data;
        }
    });
    $.ajax({
        type: "GET",
        async: false,
        url: "<?=Url::toRoute(['/hr/pick/default/groupdepartment']); ?>",
        dataType: "json",
        success: function (data) {
            affectedDepartment = data;
        }
    });
    $.ajax({
        type: "POST",
        async: false,
        url: "<?=Url::toRoute(['/hr/pick/default/affectedgroup']); ?>",
        data: {affectedDepartment: 'all'},
        dataType: "json",
        success: function (data) {
            affectedGroup = data;
        }
    });

    function getTypeList(pid, department_id) {
        var _data;
        $.ajax({
            type: "GET",
            async: false,
            url: "<?=Url::toRoute(['/hr/pick/default/gettype', 'pid' => ""]); ?>" + pid + "&department_id=" + department_id,
            dataType: "json",
            success: function (data) {
                _data = data;
            }
        });
        return _data;
    }

    function changeColumn(options) {
        $("#column_name").kendoDropDownList({
            dataTextField: "name",
            dataValueField: "id",
            dataSource: ColumnData,
            change: function (e) {
                var pid = e.sender._old;
                if (pid === '20FFDA7D-7745-4370-B834-C1DE001F81A0') {//摘對
                    typeName(false);
                    changeTypeName(options);
                    level1(options, false);
                    changeLevel1(options);
                    level2(options, false);
                    changeLevel2(options);
                    if ($("#teamentry_affected_department").data("kendoMultiSelect")) {//上個選擇是績效
                        destroyAffected(options);
                    }
                } else if (pid === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0') {//績效
                    changeAffectedDepartment(options);
                    changeAffectedGroup(options);
                    if (!$("#type_name").data("kendoDropDownList")) {//上個選擇是摘对
                        changeTypeName(options);
                        // options.model.level1_pid = pid;
                        changeLevel1(options);
                        changeLevel2(options);
                    } else {
                        levelSetDataSource(options, pid);
                    }
                } else {//摘錯
                    if (!$("#type_name").data("kendoDropDownList")) {//上個選擇是摘对
                        changeTypeName(options);
                        // options.model.level1_pid = pid;
                        changeLevel1(options);
                        changeLevel2(options);
                    } else {
                        destroyAffected(options);
                        levelSetDataSource(options, pid);
                    }
                }
            }
        });
    }

    function changeTypeName(options) {
        if (options.model.column_id === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0' || options.model.column_id === '967CA90A-19A7-430F-80B6-0901BB289307') {
            $("#type_name_message").hide();
            if (!$("#type_name").attr('required')) {
                $("#type_name").attr('required', 'required');
            }
            $("#type_name").show();
            typeName();
        } else {
            $("#type_name").hide();
            $("#type_name").removeAttr('required');
            $("#type_name_message").show();
        }
    }

    function typeName(transform = true) {
        if (transform) {
            $("#type_name").kendoDropDownList({
                dataTextField: "name",
                dataValueField: "id",
                dataSource: {
                    transport: {
                        read: function (e) {
                            $.ajax({
                                type: "GET",
                                url: "<?=Url::toRoute(['/hr/pick/default/getfourtype']); ?>",
                                dataType: "json",
                                success: function (data) {
                                    e.success(data);
                                }
                            });
                        }
                    }
                }

            });
        } else {
            $("#type_name").data("kendoDropDownList").destroy();
            $("#type_name").parent().hide();
        }

    }

    function changeLevel1(options) {
        if (options.model.column_id === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0' || options.model.column_id === '967CA90A-19A7-430F-80B6-0901BB289307') {
            $("#level1_message").hide();
            $("#level1").show();
            level1(options);
        } else {
            $("#level1").hide();
            $("#level1_message").show();
        }
    }

    function level1(options, transform = true) {
        if (transform) {
            if ($("#level1").data('kendoDropDownList')) {
                $("#level1").parent().show();
                $("#level1").hide();
            } else {
                $("#level1").kendoDropDownList({
                    dataTextField: "name",
                    dataValueField: "id",
                    dataSource: {
                        transport: {
                            read: {
                                url: "<?=Url::toRoute(['/hr/pick/default/gettype', 'pid' => ""]); ?>" + options.model.column_id + "&department_id=" + options.model.department_id,
                                dataType: "json"
                            }
                        }
                    },
                    change: function (e) {
                        var pid = e.sender._old;
                        var department_id = options.model.department_id;
                        var dataList = getTypeList(pid, department_id);
                        var dataSource = new kendo.data.DataSource({
                            data: dataList
                        });
                        $("#level2").data("kendoDropDownList").select(-1);
                        $("#level2").data("kendoDropDownList").setDataSource(dataSource);
                    }
                });
            }
        } else {
            $("#level1").parent().hide();
        }
    }

    function changeLevel2(options) {
        if (options.model.column_id === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0' || options.model.column_id === '967CA90A-19A7-430F-80B6-0901BB289307') {
            $("#level2_message").hide();
            $("#level2").show();
            level2(options);
        } else {
            $("#level2").hide();
            $("#level2_message").show();
        }
    }

    function level2(options, transform = true) {
        if (transform) {
            if ($("#level2").data('kendoDropDownList')) {
                $("#level2").parent().show();
                $("#level2").hide();
            } else {
                $("#level2").kendoDropDownList({
                    dataTextField: "name",
                    dataValueField: "id",
                    dataSource: {
                        transport: {
                            read: {
                                url: "<?=Url::toRoute(['/hr/pick/default/gettype', 'pid' => ""]); ?>" + options.model.level2_pid + "&department_id=" + options.model.department_id,
                                dataType: "json"
                            }
                        }
                    }
                });
            }
        } else {
            $("#level2").parent().hide();
        }
    }

    function levelSetDataSource(options, pid) {
        var department_id = options.model.department_id;
        var dataList = getTypeList(pid, department_id);
        var dataSource = new kendo.data.DataSource({
            data: dataList
        });
        $("#level1").data("kendoDropDownList").select(-1);
        $("#level1").data("kendoDropDownList").setDataSource(dataSource);
        $("#level2").data("kendoDropDownList").select(-1);
        $("#level2").data("kendoDropDownList").setDataSource(_dataSource);
    }

    function changeAffectedDepartment(options) {
        if (options.model.column_id === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0') {
            $("#teamentry_affected_department_message").hide();
            if (!$("#teamentry_affected_department").attr('required')) {
                $("#teamentry_affected_department").attr('required', 'required');
            }
            $("#teamentry_affected_department").show();
            affectedDepartmentInit(options);
        } else {
            $("#teamentry_affected_department_message").show();
            $("#teamentry_affected_department").removeAttr('required');
            $("#teamentry_affected_department").hide();
        }
    }

    function affectedDepartmentInit(options, transform = true) {
        if (transform) {
            if ($("#teamentry_affected_department").data('kendoMultiSelect')) {
                $("#teamentry_affected_department").parent().show();
                $("#teamentry_affected_department").hide();
            } else {
                $("#teamentry_affected_department").kendoMultiSelect({
                    dataTextField: "name",
                    dataValueField: "id",
                    dataSource: {
                        transport: {
                            read: {
                                url: "<?=Url::toRoute(['/hr/pick/default/teamentryaffecteddepartment']); ?>",
                                dataType: "json",
                                data: function () {
                                    return {department_id: options.model.department_id};
                                }
                            }
                        },
                        group: {field: "group"}
                    },
                    change: function (e) {
                        var department = this.value();
                        var dataSource = new kendo.data.DataSource({
                            transport: {
                                read: {
                                    url: "<?=Url::toRoute(['/hr/pick/default/affectedgroup']); ?>",
                                    dataType: "json",
                                    type: "POST",
                                    data: function () {
                                        return {affectedDepartment: department};
                                    }
                                }
                            },
                            group: {field: "group"}
                        });
                        $("#teamentry_affected_group").data("kendoMultiSelect").setDataSource(dataSource);
                    }
                });
            }
        } else {
            $("#teamentry_affected_department").parent().hide();
        }
    }

    function changeAffectedGroup(options) {
        if (options.model.column_id === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0') {
            $("#teamentry_affected_group_message").hide();
            $("#teamentry_affected_group").show();
            affectedGroupInit(options);
        } else {
            $("#teamentry_affected_group_message").show();
            $("#teamentry_affected_group").hide();
        }
    }

    function affectedGroupInit(options, transform = true) {
        if (transform) {
            if ($("#teamentry_affected_group").data('kendoMultiSelect')) {
                $("#teamentry_affected_group").parent().show();
                $("#teamentry_affected_group").hide();
            } else {
                $("#teamentry_affected_group").kendoMultiSelect({
                    dataTextField: "unit_name",
                    dataValueField: "id",
                    dataSource: {
                        transport: {
                            read: {
                                url: "<?=Url::toRoute(['/hr/pick/default/affectedgroup']); ?>",
                                dataType: "json",
                                type: "POST",
                                data: function () {
                                    var department = [];
                                    var length = options.model.affected_department.length;
                                    for (var o = 0; o < length; o++) {
                                        department.push(options.model.affected_department[o]);
                                    }
                                    return {affectedDepartment: department};
                                }
                            }
                        },
                        group: {field: "group"}
                    }
                });
            }
        } else {
            $("#teamentry_affected_group").parent().hide();
        }
    }

    function destroyAffected(options) {
        affectedDepartmentInit(options, false);
        changeAffectedDepartment(options);
        affectedGroupInit(options, false);
        changeAffectedGroup(options);
    }

    function changeTag() {
        $("#tag_name").kendoDropDownList({
            dataTextField: "name",
            dataValueField: "id",
            dataSource: TagList
        });
    }

    function changeRating(options) {
        $("#rating_name").kendoDropDownList({
            dataTextField: "name",
            dataValueField: "id",
            dataSource: {
                transport: {
                    read: {
                        url: "<?=Url::toRoute(['/hr/pick/default/getrating', 'department_id' => ""]); ?>" + options.model.department_id,
                        dataType: "json"
                    }
                }
            },
            change: function (e) {
                var id = e.sender._old;
                for (var o in Rating) {
                    if (id == Rating[o].id) {
                        $("#deductions_" + options.model.id).html(Rating[o].deductions_situation + "元/次");
                        $("#deductions_situation").val(Rating[o].deductions_situation + "元/次");
                    }
                }
            }
        });
    }

    $(document).ready(function () {
        $("#TeamentryList").kendoGrid({
            dataSource: {
                transport: {
                    read: function (e) {
                        $.ajax({
                            data: {'T_date_start': $("#T_date_start").val(), 'T_date_end': $("#T_date_end").val()},
                            url: "<?=Url::to(['getteamentrylist']); ?>",
                            dataType: "json",
                            success: function (redata) {
                                kendo.ui.progress(parent.teamentryWindow, false);
                                e.success(redata);
                            }
                        })
                    },
                    update: function (e) {
                        if (typeof  e.data.type_id == "object" && e.data.type_id != null) {
                            e.data.type_id = e.data.type_id['id'];
                        }
                        if (typeof e.data.level1_id == "object" && e.data.level1_id != null) {
                            e.data.level1_id = e.data.level1_id['id'];
                        }
                        if (typeof e.data.level2_id == "object" && e.data.level1_id != null) {
                            e.data.level2_id = e.data.level2_id['id'];
                        }
                        $.ajax({
                            url: "<?=Url::to(['updatateamentry']); ?>",
                            dataType: "json",
                            type: "POST",
                            data: e.data,
                            success: function (redata) {
                                if (redata.status == 1) {
                                    var Teamentry_kendo = $("#TeamentryList").data("kendoGrid");
                                    Teamentry_kendo.dataSource.read();
                                    Teamentry_kendo.refresh();
                                } else {
                                    layer.msg(redata.info, {icon: 5});
                                }
                            }
                        })
                    },
                    destroy: function (e) {
                        $.ajax({
                            url: "<?=Url::to(['destroyteamentry']); ?>",
                            type: "POST",
                            dataType: "json",
                            data: e.data,
                            success: function (redata) {
                                if (redata.status == 1) {
                                    e.success(e.data);
                                } else {
                                    layer.msg(redata.msg, {icon: 5});
                                }
                            }
                        })
                    },
                },
                schema: {
                    model: {
                        id: "id",
                        fields: {
                            id: {field: "id", editable: false, nullable: true},
                            created: {field: "created", type: "date", editable: false},
                            department_name: {field: "department_name", editable: false},
                            group_name: {field: "group_name", editable: false},
                            name_cn_long: {field: "name_cn_long", type: "string", editable: false},
                            name_en_long: {field: "name_en_long", type: "string", editable: false},
                            column_id: {field: "column_id"},
                            type_id: {field: "type_id", type: "object"},
                            level1_id: {field: "level1_id"},
                            level2_id: {field: "level2_id"},
                            content: {field: "content", type: "string"},
                            tag: {field: "tag", type: "string"},
                            tag_name: {field: "tag_name", type: "string"},
                            deductions_situation: {field: "deductions_situation", type: "string", editable: false},
                            affected_department: {field: "affected_department", type: "object"},
                            affected_group: {field: "affected_group", type: "object"}
                        }
                    }
                },
                pageSize: 20
            },
            filterable: {
                extra: false,
                operators: {
                    string: {
                        contains: "包含",
                        doesnotcontain: "不包含",
                        eq: "等于",
                        neq: "不等于"
                    }
                }
            },
            sortable: true,
            reorderable: true,
            editable: {
                mode: "popup",
                template: kendo.template($("#teamentry-popup-editor").html()),
                window: {
                    animation: {
                        close: {
                            effects: "fade:out"
                        },
                        open: {
                            effects: "fade:in"
                        }
                    },
                    close: function () {
                        $(".k-edit-form-container").remove();
                        $(document).unbind("scroll.unable");
                    }
                }
            },
            edit: function (e) {
                $(".k-edit-form-container").parent().width(800).height(680).data("kendoWindow").center();
                $(".k-edit-form-container").width("100%");
                changeColumn(e);
                changeTypeName(e);
                changeLevel1(e);
                changeLevel2(e);
                changeRating(e);
                changeAffectedDepartment(e);
                changeAffectedGroup(e);
                changeTag();
                //禁用滾動條
                var top = $(document).scrollTop();
                $(document).on('scroll.unable', function (e) {
                    $(document).scrollTop(top);
                })
            },
            toolbar: kendo.template($("#TeamentryTime").html()),
            pageable: {
                refresh: true,
                pageSizes: [20, 40, 60, "all"],
                buttonCount: 5
            },
            columns: [
                {
                    field: "created",
                    title: "美国时间",
                    format: "{0:MM/dd/yyyy HH:mm}",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "department_name",
                    title: "部门",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "group_name",
                    title: "组别",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "name_cn_long",
                    title: "中文名",
                    hidden: true,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "name_en_long",
                    title: "英文名",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute

                },
                {
                    field: "column_name",
                    title: "三类别",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute

                },
                {
                    field: "type_name",
                    title: "五大类",
                    template: function (e) {
                        if (e.column_id == '20FFDA7D-7745-4370-B834-C1DE001F81A0')
                            return "無";

                        if (typeof e.type_name == 'string')
                            return e.type_name;
                        return "";
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "level1",
                    title: "错误一级类别",
                    template: function (e) {
                        if (e.column_id == '20FFDA7D-7745-4370-B834-C1DE001F81A0')
                            return "無";
                        if (typeof e.level1 == 'string')
                            return e.level1;
                        return "";
                    },
                    hidden: false,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "level2",
                    title: "错误二级类别",
                    template: function (e) {
                        if (e.column_id == '20FFDA7D-7745-4370-B834-C1DE001F81A0')
                            return "無";
                        if (typeof e.level2 == 'string')
                            return e.level2;
                        return "";
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "content",
                    title: "详情",
                    width: "26%"
                },
                {
                    field: "affected_department",
                    title: "被影響部門",
                    width: "6%",
                    template: function (e) {
                        if (e.column_id === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0') {
                            var departmentNames = new Array();
                            for (var b = 0; b < e.affected_department.length; b++) {
                                for (var o in affectedDepartment) {
                                    if (affectedDepartment[o].id == e.affected_department[b]) {
                                        departmentNames.push(affectedDepartment[o].name);
                                    }
                                }
                            }
                            return departmentNames;
                        }
                        return "無";
                    }
                },
                {
                    field: "affected_group",
                    title: "被影響組別",
                    width: "6%",
                    template: function (e) {
                        if (e.column_id === '14322B1D-B19F-4FE3-8779-F29D66C5FFE0') {
                            var groupNames = new Array();
                            for (var b = 0; b < e.affected_group.length; b++) {
                                for (var o in affectedGroup) {
                                    if (affectedGroup[o].id == e.affected_group[b]) {
                                        groupNames.push(affectedGroup[o].unit_name);
                                    }
                                }
                            }
                            if (groupNames.length > 0) {
                                return groupNames;
                            } else {
                                var html = "";
                                for (var b = 0; b < e.affected_department.length; b++) {
                                    for (var o in affectedDepartment) {
                                        if (affectedDepartment[o].id == e.affected_department[b]) {
                                            if (affectedDepartment[o].hasChildren) {
                                                html = "未選擇";
                                            } else {
                                                html = "無";
                                            }
                                        }
                                    }
                                }
                                return html;
                            }
                        }
                        return "無";

                    }
                },
                {
                    field: "tag_name",
                    title: "警告信",
                    template: function (e) {
                        if (e.column_id == '20FFDA7D-7745-4370-B834-C1DE001F81A0')
                            return "無";
                        return e.tag_name;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                <?php if(isset($department) && $department == 1):?>
                {
                    field: "rating_name",
                    title: "评级",
                    template: function (e) {
                        if (e.column_id == '20FFDA7D-7745-4370-B834-C1DE001F81A0') {
                            return "無";
                        }
                        if (e.rating_name == null) {
                            return "";
                        }
                        return e.rating_name;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "deductions_situation",
                    title: "扣款情况",
                    template: function (e) {
                        if (e.column_id == '20FFDA7D-7745-4370-B834-C1DE001F81A0')
                            return "無";
                        if (e.deductions_situation == null) {
                            return "<span id='deductions_" + e.id + "'>0元</span>";
                        } else {
                            return "<span id='deductions_" + e.id + "'>" + e.deductions_situation + "元</span>";
                        }
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                <?php endif?>
                {
                    command: ["edit", 'destroy'],
                    title: "操作",
                    width: "7%",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                }
            ],
            dataBound: function () {
                dataView = this.dataSource.view();
                for (var i = 0; i < dataView.length; i++) {
                    if (dataView[i].rating_id != "0") {
                        var uid = dataView[i].uid;
                        $("#TeamentryList").find("tr [data-uid='" + uid + "']").css('background', '#66FF66');
                    }
                    /*else if (dataView[i].is_audit==1) {
                                            var uid = dataView[i].uid;
                                            $("#TeamentryList").find("[data-uid='" + uid + "']").css('background','	#888888');
                                        }*/
                }
            }
        });
        $("#T_date_start").kendoDatePicker({
            format: "yyyy/MM/dd",
            change: function (e) {
                var __grid = $("#TeamentryList").data("kendoGrid");
                __grid.dataSource.read();
                __grid.refresh();
            }
        });
        $("#T_date_end").kendoDatePicker({
            format: "yyyy/MM/dd",
            change: function (e) {
                var __grid = $("#TeamentryList").data("kendoGrid");
                __grid.dataSource.read();
                __grid.refresh();
            }
        });
    });
</script>
